
namespace org.openERP.erpCommon.ad_callouts;

using org.openERP.Base.secureApp.VariablesSecureApp;
using org.openERP.xmlEngine.XmlDocument;
using org.openERP.erpCommon.utility.*;
using java.io.*;
using javax.servlet.*;
using javax.servlet.http.*;

public class ComboReloads101 extends CalloutHelper {

  void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTabId, String windowId) throws IOException, ServletException {
    log4j.debug("Output: dataSheet");
    XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openERP/erpCommon/ad_callouts/CallOut").createXmlDocument();
    

    StringBuffer resultado = new StringBuffer();
    boolean isFirst=true;
    ComboTableData comboTableData = null;
    resultado.append("var calloutName='ComboReloads101';\n\n");
    resultado.append("var respuesta = new Array(\n");
    
    if (vars.commandIn("inpadReferenceId")) {
      try {
        if (!isFirst) resultado.append(", \n");
        comboTableData = new ComboTableData(vars, this, "18", "AD_Reference_Value_ID", "4", "115", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
        Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, "");
        resultado.append("new Array(\"inpadReferenceValueId\", ");
        resultado.append(generateArray(comboTableData.select(false)));
        comboTableData = null;
        resultado.append(")");
        isFirst=false;
      } catch (ServletException ex) {
        OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex.toString());
        bdErrorHidden(response, myError.getType(), myError.getTitle(), myError.getMessage());
        return;
      } catch (Exception ex1) {
        OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex1.toString());
        bdErrorHidden(response, myError.getType(), myError.getTitle(), myError.getMessage());
        return;
      }
    }
    
    if (vars.commandIn("inpadClientId", "inpadClientId", "inp#userClient", "inp#userOrg")) {
      try {
        if (!isFirst) resultado.append(", \n");
        comboTableData = new ComboTableData(vars, this, "19", "AD_Org_ID", "", "104", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
        Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, "");
        resultado.append("new Array(\"inpadOrgId\", ");
        resultado.append(generateArray(comboTableData.select(false)));
        comboTableData = null;
        resultado.append(")");
        isFirst=false;
      } catch (ServletException ex) {
        OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex.toString());
        bdErrorHidden(response, myError.getType(), myError.getTitle(), myError.getMessage());
        return;
      } catch (Exception ex1) {
        OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex1.toString());
        bdErrorHidden(response, myError.getType(), myError.getTitle(), myError.getMessage());
        return;
      }
    }
    
    if (vars.commandIn("inp#userClient")) {
      try {
        if (!isFirst) resultado.append(", \n");
        comboTableData = new ComboTableData(vars, this, "19", "AD_Client_ID", "", "103", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
        Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, "");
        resultado.append("new Array(\"inpadClientId\", ");
        resultado.append(generateArray(comboTableData.select(false)));
        comboTableData = null;
        resultado.append(")");
        isFirst=false;
      } catch (ServletException ex) {
        OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex.toString());
        bdErrorHidden(response, myError.getType(), myError.getTitle(), myError.getMessage());
        return;
      } catch (Exception ex1) {
        OBError myError = Utility.translateError(this, vars, vars.getLanguage(), ex1.toString());
        bdErrorHidden(response, myError.getType(), myError.getTitle(), myError.getMessage());
        return;
      }
    }
    
    resultado.append("\n);");

    xmlDocument.setParameter("array", resultado.toString());
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
  }

}
